In [8]:
class vector:
def __init__(self, a, b):
self.x = a
self.y = b
return None
def __add__(self, v):
bla = vector(self.x + v.x, self.y + v.y)
return bla
In [13]:
a = vector(1.1, 4.3)
b = vector(4.2,9.4352)
c = a + b #calling the add method, self is a and v is b. it creates a new vector object.
print (c.x, c.y)
This is a two-dimensional array because we can uniquely label the elements of the matrix by two numbers $i,j$ via the identification $a_{i,j}$.
In [57]:
import numpy as np
a = np.zeros((3,3), dtype = np.float)
b = np.ones((3,3), dtype = np.int)
I = np.array([[1,0,0],
[0,1,0],
[0,0,1]])
c = I*2*b
print a, type(a)
print b, type(b)
print c, type(I)
In [ ]: